<template>
    <div class="page-book">
        <div class="page-book-item" v-for="(item, index) in book" :key="index">
            <div class="page-book-header">
                <div class="page-book-itemtitle">{{ item.name }}</div>
                <div class="page-book-opitons"></div>
            </div>
            <div class="page-book-children" v-if="item.show">
                <sub-book v-for="(child, cindex) in item.children" :key="cindex" :item="child" :index="cindex" @emitshow="emitshow(index,$event)"></sub-book>
            </div>
        </div>
    </div>
</template>

<script setup>
import { ref } from 'vue'
import subBook from './subbook.vue'
const book = ref([
    {
        name: '广东',
        show: true,
        children: [
            {
                name: '对讲机组',
                show: false,
                children: [
                    {
                        name: '范金盛终端'
                    },
                    {
                        name: '范金盛终端'
                    },
                    {
                        name: '范金盛终端'
                    },
                    {
                        name: '范金盛终端'
                    },
                    {
                        name: '范金盛终端'
                    },
                    {
                        name: '范金盛终端'
                    },
                    {
                        name: '范金盛终端'
                    },
                    {
                        name: '范金盛终端'
                    }
                ]
            },
            {
                name: '深圳',
                show: false,
                children: [
                    {
                        name: '范金盛终端'
                    },
                    {
                        name: '范金盛终端'
                    },
                    {
                        name: '范金盛终端'
                    },
                    {
                        name: '范金盛终端'
                    },
                    {
                        name: '范金盛终端'
                    },
                    {
                        name: '范金盛终端'
                    },
                    {
                        name: '范金盛终端'
                    },
                    {
                        name: '范金盛终端'
                    }
                ]
            }
        ]
    }
])
const emitshow = (e, typeindex) => { 
    book.value[e].children = book.value[e].children.map((item, index) => {
        return {
            ...item,
            show: index == typeindex ? !item.show : false
        }
    }) 
}
</script>

<style lang="scss" scoped>
.page-book{
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    &-item{

    }
    &-header{
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        font-size: 14px;
        color: #fff;
        margin-bottom: 8px;
        align-items: center;
    }
    &-opitons{
        height: 24px;
        width: 24px;
        background: url("@/assets/home/downicon.png") center center no-repeat;
        background-size: 24px auto;
    }
}
</style>